package cn.lhf.cd.controller;

import cn.lhf.cd.Main;
import cn.lhf.cd.annotation.FXController;
import cn.lhf.cd.mapper.UserMapper;
import javafx.scene.control.Label;
import org.apache.ibatis.session.SqlSession;

import java.math.BigDecimal;
import java.net.URL;
import java.util.ResourceBundle;

@FXController(path = "/ui/check_balance.fxml")
public class CheckBalanceController extends ChildrenController {
    public Label idLabel;
    public Label moneyLabel;

    @Override
    public String getTitle() {
        return "余额查询窗口";
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }

    @Override
    public void bind(MainController mainController, Object ... args) {
        super.bind(mainController, args);
        Integer id = getMainController().getSelfId();
        setId(id);  //显示帐号
        SqlSession sqlSession = Main.openSqlSession();
        setMoney(sqlSession.getMapper(UserMapper.class).getMoney(id));  //显示余额
        sqlSession.close();
    }

    @Override
    public void onBtnRight4() throws Exception {
        getMainController().goHome();
    }

    public void setId(Integer id) {
        idLabel.setText("" + id);
    }

    public void setMoney(BigDecimal decimal) {
        moneyLabel.setText("" + decimal);
    }
}
